/*
 * Copyright (c) 2017年11月10日  by XuanWu Wireless Technology Co., Ltd 
 *             All rights reserved  
 */
package com.zml.twelfth.example.observable;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author <a href="mailto:zhaominglin@wxchina.com">minglin.Zhao</a>
 * @Description
 * @Date 2017/11/10
 * @Version 1.0.0
 */
public class Observable implements Quackservable {
    ArrayList observers = new ArrayList();
    Quackservable duck;

    public Observable(Quackservable duck) {
        this.duck = duck;
    }

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void notifyObservers() {
        Iterator iterator = observers.iterator();
        while (iterator.hasNext()){
            Observer observer = (Observer) iterator.next();
            observer.update(duck);
        }
    }
}
